/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package student;

import common.*;
import java.io.BufferedOutputStream;
import java.io.ObjectOutputStream;
import java.net.Socket;

/**
 * Tcp套接字消息发送线程
 * 
 * @author Eugene-Forest
 */
public class SendThread extends Thread{
    
    private Socket socket;
    
    private MessageModel messageModel;

    public SendThread(Socket socket, MessageModel messageModel) {
        this.socket = socket;
        this.messageModel = messageModel;
    }

    @Override
    public void run() {
        try {
            //没有判断套接字是否关闭，可能会出错
            ObjectOutputStream oos=new ObjectOutputStream(new BufferedOutputStream(socket.getOutputStream()));
            oos.writeObject(messageModel);
            oos.flush();
        } catch (Exception e) {
           e.printStackTrace();
        }
    }
}
